/**
 * Copyright © FEITIAN Technologies Co., Ltd. All Rights Reserved.
 * https://www.ftsafe.com/
 */
#ifndef __FEITIAN_FS_PORT_H__
#define __FEITIAN_FS_PORT_H__
#include "ft_main.h"
#include <stdint.h>
#include "lfs.h"

#define FEITIAN_FS_O_RDONLY    LFS_O_RDONLY      /*只读*/
#define FEITIAN_FS_O_WRONLY    LFS_O_WRONLY      /*只写*/
#define FEITIAN_FS_O_RDWR      LFS_O_RDWR        /*读写*/
#define FEITIAN_FS_O_APPEND    LFS_O_APPEND      /*每次写时移动到文件的末尾*/
#define FEITIAN_FS_O_CREAT     LFS_O_CREAT       /*如果文件不存在就创建*/
#define FEITIAN_FS_O_TRUNC     LFS_O_TRUNC       /*将当前文件截断为0字节*/
#define FEITIAN_FS_O_EXCL      LFS_O_EXCL        /*如果文件存在则失败*/
#define FEITIAN_FS_O_SYNC

#define FEITIAN_FS_SEEK_SET    LFS_SEEK_SET     /*相对于绝对位置查找*/
#define FEITIAN_FS_SEEK_CUR    LFS_SEEK_CUR     /*相对于当前文件位置查找*/
#define FEITIAN_FS_SEEK_END    LFS_SEEK_END     /*相对于文件的末尾查找*/

typedef int feitian_fs_t;

/********************************** 文件系统操作 ******************************/

/**
 * @brief  文件系统初始化
 * @note   
 * @retval None
 */
void feitian_fs_init(void);
/**
 * @brief  文件系统格式化
 * @note   
 * @retval None
 */
void feitian_fs_format(void);

/**
 * @brief  获取文件系统剩余空间
 * @note   
 * @retval None
 */
void feitian_get_fs_size(void);

/* *********************************** 目录操作函数 ****************************/

/**
 * @brief  创建目录
 * @note   
 * @param  *path: 
 * @retval 
 */
int32_t feitian_fs_mkdir(const char *path);

/*********************************** 文件操作函数 ******************************/

/**
 * @brief  打开文件
 * @note   
 * @param  *pathname:  
 * @param  opt: 
 * @retval 
 */
feitian_fs_t feitian_fs_file_open(const uint8_t *pathname, uint32_t opt);

/**
 * @brief  读文件
 * @note   
 * @param  fd: 
 * @param  *buff: 
 * @param  size: 
 * @retval 
 */
int32_t feitian_fs_file_read(feitian_fs_t fd, uint8_t *buff, uint32_t size);

/**
 * @brief  写文件
 * @note   
 * @param  fd: 
 * @param  *buff: 
 * @param  size: 
 * @retval 
 */
int32_t feitian_fs_file_write(feitian_fs_t fd, uint8_t *buff, uint32_t size);

/**
 * @brief  文件查找
 * @note   
 * @param  fd: 
 * @param  offset: 
 * @param  opt: 
 * @retval 
 */
int32_t feitian_fs_file_seek(feitian_fs_t fd, uint32_t offset, uint32_t opt);

/**
 * @brief  文件关闭
 * @note   
 * @param  fd: 
 * @retval 
 */
int32_t feitian_fs_file_close(feitian_fs_t fd);

/**
 * @brief  文件大小
 * @note   
 * @param  fd: 
 * @retval  
 */
int32_t feitian_fs_file_size(feitian_fs_t fd);

/**
 * @brief  文件删除
 * @note   
 * @param  *path: 
 * @retval None
 */
void feitian_fs_file_delete(const char *path);

/**
 * @brief  文件重命名
 * @note   
 * @param  *oldpath: 
 * @param  *newpath: 
 * @retval 
 */
int32_t feitian_fs_file_rename(const char *oldpath, const char *newpath);

#if 0
    int32_t feitian_read_file(const char *path, void *dst, uint32_t size);
    int32_t feitian_write_file(const char *path, void *dst, uint32_t size);
#endif

#endif /* __FEITIAN_FS_PORT_H__ */
